home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / hsrc_117.zip / WRITLINE.C < prev   
Text File  |  1990-11-09  |  1KB  |  65 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.  
  7. /* Return a line from a message */
  8.  
  9. char * pascal write_line (char **text,word linelen,char ctla) {
  10.  
  11.     static char line[133];
  12.     word register x=0;
  13.     char *p;
  14.     char *pp;
  15.  
  16.     if(!*text) return "";
  17.     if(!**text) return *text;
  18.     p=*text;
  19.     pp=line;
  20.     *pp=0;
  21.     while(++x<(linelen+1) && *p && *p!='\r') {
  22.         if(*p=='\n' || *p=='\x8d') {
  23.             p++;
  24.             continue;
  25.         }
  26.         if((*p=='\01' && (*(p-1)=='\r' || p==*text)) && !ctla) {
  27.             while(*p!='\r' && *p)p++;
  28.             if(*p=='\r') p++;
  29.             continue;
  30.         }
  31.         *pp++=*p++;
  32.         *pp=0;
  33.     }
  34.     if(*p=='\r') {
  35.         *pp=0;
  36.         p++;
  37.     }
  38.     else if(*p==' ') {
  39.         *pp=0;
  40.         while(*p==' ') p++;
  41.     }
  42.     else if(x==(linelen+1)) {
  43.         if(strchr(line,' ')) {
  44.             while(p>*text && *pp!=' ') {
  45.                 *pp=0;
  46.                 pp--;
  47.                 p--;
  48.             }
  49.             if(p==*text) {
  50.                 strncpy(line,*text,linelen+1);
  51.                 line[linelen+1]=0;
  52.                 p=text[linelen+1];
  53.             }
  54.             else p++;
  55.         }
  56.     }
  57.     while(*pp==' ' && pp>line) {    /* Rstrip returned string */
  58.         *pp=0;
  59.         --pp;
  60.     }
  61.     *text=p;
  62.     return line;
  63. }
  64.  
  65.